package com.softserveinc.autorent.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the car database table.
 * 
 */
@Entity
@Table(name="car")
@NamedQueries({
@NamedQuery(name = "Car.findAll", query = "SELECT c FROM Car c"),
@NamedQuery(name = "Car.findById", query = "SELECT c FROM Car c WHERE c.id = :id"),
@NamedQuery(name = "Car.findAllByCarModelId", query = "SELECT c FROM Car c WHERE c.carModel.id = :id"),
@NamedQuery(name = "Car.findAllByCarVendorId", query = "SELECT c FROM Car c WHERE c.carModel.carVendor.id = :id"),
@NamedQuery(name = "Car.findAllByCarStatus", query = "SELECT c FROM Car c WHERE c.status = :status")
})
public class Car implements Serializable {
	private static final long serialVersionUID = -5635838391811387926L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private int id;

	@Column(name="car_class", nullable=false, length=10)
	@Enumerated(EnumType.STRING)
	private CarClassEnum carClass;

	@Column(length=20)
	@Enumerated(EnumType.STRING)
	private CarColorEnum color;

	@Column(name="make_year")
	private int makeYear;

	@Column(nullable=false, length=45)
	private String number;

	@Temporal(TemporalType.DATE)
	@Column(name="start_date")
	private Date startDate;

	@Column(name="start_mileage")
	private int startMileage;

	@Column(nullable=false, length=45)
	private String vin;
	
	@Column(nullable=false, length=50)
	@Enumerated(EnumType.STRING)
	private CarStatusEnum status;

	//bi-directional many-to-one association to CarModel
	@ManyToOne
	@JoinColumn(name="car_model_id", nullable=false)
	private CarModel carModel;


	//bi-directional many-to-one association to Order
	@OneToMany(mappedBy="car")
	private List<Order> orders;

	public Car() {
	}
	

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public CarClassEnum getCarClass() {
		return this.carClass;
	}

	public void setCarClass(CarClassEnum carClass) {
		this.carClass = carClass;
	}

	public CarColorEnum getColor() {
		return this.color;
	}

	public void setColor(CarColorEnum color) {
		this.color = color;
	}

	public int getMakeYear() {
		return this.makeYear;
	}

	public void setMakeYear(int makeYear) {
		this.makeYear = makeYear;
	}

	public String getNumber() {
		return this.number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public Date getStartDate() {
		return this.startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public int getStartMileage() {
		return this.startMileage;
	}

	public void setStartMileage(int startMileage) {
		this.startMileage = startMileage;
	}

	public String getVin() {
		return this.vin;
	}

	public void setVin(String vin) {
		this.vin = vin;
	}

	public CarModel getCarModel() {
		return this.carModel;
	}

	public void setCarModel(CarModel carModel) {
		this.carModel = carModel;
	}


	public List<Order> getOrders() {
		return this.orders;
	}

	public void setOrders(List<Order> orders) {
		this.orders = orders;
	}


	public CarStatusEnum getStatus() {
		return status;
	}


	public void setStatus(CarStatusEnum name) {
		this.status = name;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((carClass == null) ? 0 : carClass.hashCode());
		result = prime * result
				+ ((carModel == null) ? 0 : carModel.hashCode());
		result = prime * result + ((color == null) ? 0 : color.hashCode());
		result = prime * result + id;
		result = prime * result + makeYear;
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		result = prime * result + ((orders == null) ? 0 : orders.hashCode());
		result = prime * result
				+ ((startDate == null) ? 0 : startDate.hashCode());
		result = prime * result + startMileage;
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((vin == null) ? 0 : vin.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Car other = (Car) obj;
		if (carClass != other.carClass)
			return false;
		if (carModel == null) {
			if (other.carModel != null)
				return false;
		} else if (!carModel.equals(other.carModel))
			return false;
		if (color != other.color)
			return false;
		if (id != other.id)
			return false;
		if (makeYear != other.makeYear)
			return false;
		if (number == null) {
			if (other.number != null)
				return false;
		} else if (!number.equals(other.number))
			return false;
		if (orders == null) {
			if (other.orders != null)
				return false;
		} else if (!orders.equals(other.orders))
			return false;
		if (startDate == null) {
			if (other.startDate != null)
				return false;
		} else if (!startDate.equals(other.startDate))
			return false;
		if (startMileage != other.startMileage)
			return false;
		if (status != other.status)
			return false;
		if (vin == null) {
			if (other.vin != null)
				return false;
		} else if (!vin.equals(other.vin))
			return false;
		return true;
	}

}